<?php

class Code extends Controller {

	function Code()
	{
		parent::Controller();
	}

    /**
	 * genarate authcode image
	 */
	function admincode($r){
		$this->load->library('session');
		Header("Content-type: image/PNG");
		$authlist = "ABCDEFGHIJKLMNPQRSTUVWXYZ123456789";
		$fitst  = substr($authlist,rand(0,33),1);
		$secnd  = substr($authlist,rand(0,33),1);
		$third  = substr($authlist,rand(0,33),1);
		$fourth = substr($authlist,rand(0,33),1);

		$authcode = $fitst.$secnd.$third.$fourth;

		$this->session->set_userdata('admincode',strtoupper($authcode));
		srand((double)microtime()*1000000);
		$im = imagecreate(62,20);
		$white = ImageColorAllocate($im, 255,255,255);
		$black = ImageColorAllocate($im, 0,0,0);
		imagefill($im,68,30,$white);

		imagestring($im, 12, 10, 3, $authcode, $black);

		for($i=0;$i<100;$i++){
		    $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
		    imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
		}

		ImagePNG($im);
		ImageDestroy($im);
	}

    function message($r){
		$this->load->library('session');
		Header("Content-type: image/PNG");
		$authlist = "ABCDEFGHIJKLMNPQRSTUVWXYZ123456789";
		$fitst  = substr($authlist,rand(0,33),1);
		$secnd  = substr($authlist,rand(0,33),1);
		$third  = substr($authlist,rand(0,33),1);
		$fourth = substr($authlist,rand(0,33),1);

		$authcode = $fitst.$secnd.$third.$fourth;

		$this->session->set_userdata('message_code',strtoupper($authcode));
		srand((double)microtime()*1000000);
		$im = imagecreate(62,20);
		$white = ImageColorAllocate($im, 255,255,255);
		$black = ImageColorAllocate($im, 0,0,0);
		imagefill($im,68,30,$white);

		imagestring($im, 12, 10, 3, $authcode, $black);

		for($i=0;$i<100;$i++){
		    $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
		    imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
		}

		ImagePNG($im);
		ImageDestroy($im);
	}

}
?>